/*
 * TMap Designer - A Thematic Map design software
 * Copyright (C) 2006 World Health Organization
 * http://www.who.int
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package who.tmap.ui;

import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JPanel;

import org.apache.log4j.Logger;

import who.tmap.bo.Annotations;

/**
 * A Dialog to edit proportional symbols legend
 * @author stl
 *
 */
public class JDialogEditProportionalSymbolsLegend extends JDialog {

    private static Logger logger = Logger.getLogger( JDialogEditProportionalSymbolsLegend.class );	
	
    private Annotations annotations;

	private JPanel jContentPane = null;

	private JPanel jPanelButtons = null;
	private JPanel jPanelBoundaryFormat = null;
	private JPanel jPanelControls = null;	

	private JButton jButtonOK = null;
	private JButton jButtonCancel = null;
	private JCheckBox jCheckBoxRoundRanges = null;

	/**
	 * This is the default constructor
	 */
	public JDialogEditProportionalSymbolsLegend( Frame parent, boolean modal, Annotations annotations ) {
		super( parent, modal );
		
		this.annotations =annotations;
		
		getJCheckBoxRoundRanges().setSelected( annotations.isProportionalSymbolsRoundValues() );
		
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(300, 150);
		this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		this.setTitle( "Edit Proportional Symbols Legend" );
		this.setContentPane(getJContentPane());
		this.setLocationRelativeTo(null);
		
		getRootPane().setDefaultButton( getJButtonOK() );
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.setBorder(javax.swing.BorderFactory.createEmptyBorder(5,5,5,5));
			jContentPane.add(getJPanelControls(), java.awt.BorderLayout.SOUTH);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jButtonClose	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonCancel() {
		if (jButtonCancel == null) {
			jButtonCancel = new JButton();
			jButtonCancel.setText("Cancel");
			jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					dispose();
				}
			});
		}
		return jButtonCancel;
	}

	/**
	 * This method initializes jPanelButton	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelButtons() {
		if (jPanelButtons == null) {
			jPanelButtons = new JPanel();
			jPanelButtons.add(getJButtonOK(), null);
			jPanelButtons.add(getJButtonCancel(), null);
		}
		return jPanelButtons;
	}
	
	private JPanel getJPanelControls() {
		if (jPanelControls == null) {
			jPanelControls = new JPanel();
			jPanelControls.setLayout( new GridLayout(2,1,5,5) );
			jPanelControls.add( getJPanelBoundaryFormat() );
			jPanelControls.add( getJPanelButtons() );			
		}
		return jPanelControls;
	}
	
	private JPanel getJPanelBoundaryFormat() {
		if (jPanelBoundaryFormat == null) {
			jPanelBoundaryFormat = new JPanel();
			jPanelBoundaryFormat.add(getJCheckBoxRoundRanges(), null);
		}
		return jPanelBoundaryFormat;
	}		

	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonOK() {
		if (jButtonOK == null) {
			jButtonOK = new JButton();
			jButtonOK.setText("OK");
			jButtonOK.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					annotations.setProportionalSymbolsRoundValues( getJCheckBoxRoundRanges().isSelected() );
					dispose();
				}
			});
		}
		return jButtonOK;
	}

	
	public Annotations getAnnotations() {
		return annotations;
	}

	/**
	 * This method initializes jCheckBoxRoundRanges	
	 * 	
	 * @return javax.swing.JCheckBox	
	 */
	private JCheckBox getJCheckBoxRoundRanges() {
		if (jCheckBoxRoundRanges == null) {
			jCheckBoxRoundRanges = new JCheckBox();
			jCheckBoxRoundRanges.setText("Round values");
		}
		return jCheckBoxRoundRanges;
	}

}
